<?php

class Bill_Form_Bill extends Zend_Form
{

    public function init()
    {
        $this->setAttrib('id', 'billForm');
	
	$bill_id = new Zend_Dojo_Form_Element_TextBox('bill_id');
	$bill_id->setLabel('bill_id');
	$bill_id->setAttrib('readOnly', 'true');
	
	$bill_number = new Zend_Dojo_Form_Element_TextBox('bill_number');
	$bill_number->setLabel('bill_number');
	
	$bill_date = new Zend_Dojo_Form_Element_DateTextBox('bill_date');
	$bill_date->setLabel('bill_date');
	
	$customer_id = new Zend_Dojo_Form_Element_FilteringSelect('customer_id');
	$customer_id->setLabel('customer_id');
	$customer_id->setMultiOptions($this->getCustomer());
	$customer_id->setDijitParam('onChange', 'changeCustomer()');
	
	$address_name1 = new Zend_Dojo_Form_Element_TextBox('address_name1');
	$address_name1->setLabel('address_name1');
	
	$address_name2 = new Zend_Dojo_Form_Element_TextBox('address_name2');
	$address_name2->setLabel('address_name2');
	
	$address_street = new Zend_Dojo_Form_Element_TextBox('address_street');
	$address_street->setLabel('address_street');
	
	$address_zipcode = new Zend_Dojo_Form_Element_TextBox('address_zipcode');
	$address_zipcode->setLabel('address_zipcode');
	
	$address_city = new Zend_Dojo_Form_Element_TextBox('address_city');
	$address_city->setLabel('address_city');
	
	$bill_submit =  new Zend_Dojo_Form_Element_Button('bill_submit');
	$bill_submit->setLabel('save');
	$bill_submit->setDijitParam('onClick', 'saveBill()');
	
	
//	$addressGroup->addElement($address_name1);
	
	
	$this->addElements(array(
	    $bill_id,
	    $bill_number,
	    $customer_id,
	    $bill_date,
	    $address_name1,
	    $address_name2,
	    $address_street,
	    $address_zipcode,
	    $address_city
	));
	
	$addressGroup = $this->addDisplayGroup(array(
	    'address_name1',
	    'address_name2',
	    'address_street',
	    'address_zipcode',
	    'address_city'
	), 'addressGroup');
	
	$this->addElement($bill_submit);
    }
    
    private function getCustomer()
    {
	$addressModel = new Address_Model_DbTable_Address();
	$items = $addressModel->fetchAll(null, 'name1')->toArray();
	$arrData = array();
	foreach ($items as $item)
	{
	    $row = array();
	    $row[$item['address_id']] = $item['name1'];
	    $arrData[] = $row;
	}
	return $arrData;
    }


}

